//
//  WelcomeView.m
//  B段项目
//
//  Created by dllo on 15/11/16.
//  Copyright © 2015年 谢美娜. All rights reserved.
//

#import "WelcomeView.h"
#import "Header.h"

@implementation WelcomeView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.nameArray = @[@"欢迎页1", @"欢迎页4", @"欢迎页3", @"欢迎页5"];
        
        self.scrollView = [[UIScrollView alloc]initWithFrame:self.frame];
        _scrollView.contentSize = CGSizeMake(self.frame.size.width * _nameArray.count, self.frame.size.height);
        _scrollView.pagingEnabled = YES;
        _scrollView.delegate = self;
        _scrollView.contentOffset = CGPointMake(0, 0);
        
        for (NSInteger i = 0; i < _nameArray.count; i++) {
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.frame.size.width * i, 0, self.frame.size.width, self.frame.size.height)];
            imageView.image = [UIImage imageNamed:_nameArray[i]];
            [_scrollView addSubview:imageView];
        }
        
        [self addSubview:_scrollView];
        
        _button = [UIButton buttonWithType:UIButtonTypeSystem];
        _button.frame = CGRectMake(320 * FitWidth, 30 * FitHeight, 40 * FitWidth, 40 * FitHeight);
        _button.layer.masksToBounds = YES;
        _button.layer.cornerRadius = 20 * FitWidth;
        _button.backgroundColor = [UIColor whiteColor];
        _button.alpha = .5;
        [_button setTitle:@"跳过" forState:UIControlStateNormal];
        [self addSubview:_button];
        [_button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}


-(void)buttonAction{
    [UIView animateWithDuration:1 animations:^{
        self.alpha = 0;
        self.userInteractionEnabled = NO;
    }];
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (_scrollView.contentOffset.x > self.frame.size.width * (_nameArray.count - 1) + 50 * FitWidth) {
        [self buttonAction];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
